<template>
  <div style="margin-top: 5%;">
  <form enctype="multipart/form-data" id="fromList">
        <input type="file" name="file" multiple/><br />
      </form>
        <el-button
          type="success"
          @click="uploadObject()"
          style="margin-right:1%"
          >添加</el-button>
        <el-button
          type="primary"
          @click="addworkerpush()"
          >返回</el-button>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        visible_0:false,
        ps:this.$store.state.permission,
      };
    },
    // 注意：data即使不需要传数据，也必须return,否则会报错
    methods: {
      addworkerpush() {
        this.$router.push('/manage/addworker')
      },
      uploadObject() {
        var form = document.getElementById("fromList");
        var file = new FormData(form);
        if(this.ps=="超管"){
        this.$axios
          .post("/api/taoyun/v1/SAdmin/userManage/AddUserBatch?Id="+this.$store.state.userId, file)
          .then(res => {
            if (res.data.code == "200") {
              this.$message({
                type: "success",
                message: "添加成功"
              });
             this.$router.push('/manage/workerinfo');
            } else if (res.data.code == "500") {
             this.$message({
               type: "error",
               message: "添加失败"
             });
            }
          })
          .catch(err => {
            console.log(err);
          });
          }
          if(this.ps=="管理员"){
            this.$axios
              .post("/api/taoyun/v1/Admin/userManage/AddUserBatch?Id="+this.$store.state.userId, file)
              .then(res => {
                if (res.data.code == "200") {
                  this.$message({
                    type: "success",
                    message: "添加成功"
                  });
                  this.$router.push('/manage/workerinfo');
                } else if (res.data.code == "500") {
                 this.$message({
                   type: "error",
                   message: "添加失败"
                 });
                }
              })
              .catch(err => {
                console.log(err);
              });
          }
      },
    }
  }
</script>

<style>
</style>
